package administrator;

import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import java.util.List;

import home.HomePage;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

import controllers.Account;
import controllers.Logs;
import controllers.Registered;
import controllers.StudentInformation;

public class ManageAccounts extends WebPage {
	
	Reader reader = Resources.getResourceAsReader("sqlMapConfig.xml");
	SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
	

	public ManageAccounts() throws IOException, SQLException 
	{
		add(new BookmarkablePageLink("home", AdministratorHome.class));
		add(new BookmarkablePageLink("logoutPage", HomePage.class));
		add(new BookmarkablePageLink("addAccount", AddAccount.class));
		
		Account president = (Account)sqlMap.queryForObject("Account.getStudent", 1);
		String id = president.getStudent_id(1);
		
		StudentInformation info = (StudentInformation)sqlMap.queryForObject("StudentInformation.MyInformation", id);
		
		Form form = new Form("viewInfo");
	
		String pname = info.getStudent_firstName() + " " + info.getStudent_middleName() + " " + info.getStudent_lastName();
		
		form.add(new Label("pname", pname));
		form.add(new Label("pstudentid", id));
		form.add(new Label("pyearlevel", info.getStudent_yearlvl()));
		
		Account secretary = (Account)sqlMap.queryForObject("Account.getStudent", 2);
		String secretaryid = secretary.getStudent_id(1);
		
		StudentInformation secretaryinfo = (StudentInformation)sqlMap.queryForObject("StudentInformation.MyInformation", secretaryid);
		
		String sname = secretaryinfo.getStudent_firstName() + " " + secretaryinfo.getStudent_middleName() + " " + secretaryinfo.getStudent_lastName();
		
		form.add(new Label("sname", sname));
		form.add(new Label("sstudentid", secretaryid));
		form.add(new Label("syearlevel", secretaryinfo.getStudent_yearlvl()));
		
		Account treasurer = (Account)sqlMap.queryForObject("Account.getStudent", 3);
		String treasurerid = treasurer.getStudent_id(1);
		
		StudentInformation treasurerinfo = (StudentInformation)sqlMap.queryForObject("StudentInformation.MyInformation", treasurerid);
		
		String tname = treasurerinfo.getStudent_firstName() + " " + treasurerinfo.getStudent_middleName() + " " + treasurerinfo.getStudent_lastName();
		
		form.add(new Label("tname", tname));
		form.add(new Label("tstudentid", treasurerid));
		form.add(new Label("tyearlevel", treasurerinfo.getStudent_yearlvl()));
		
		add(form);
	}
}
